﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title></title>
	<link href="js-console.css" rel="stylesheet" />
	<!-- 2. Write a script that shows the sign (+ or -) of the product
			of three real numbers without calculating it.
			Use a sequence of if statements. -->
</head>
<body>
	<div id="js-console"></div>
	<script src="js-console.js"></script>
	<script>
		//Read input
		var first = prompt("Enter first number");
		var second = prompt("Enter second number");
		var third = prompt("Enter third number");

		if (!isNaN(first) && !isNaN(second) && !isNaN(third)) {
			first *= 1; second *= 1; third *= 1;	// make them real number

			// Calculate the product
			var result = "";
			if (first == 0 || second == 0 || third == 0) {
				result = "0";
			}
			else {
				var firstIsPositive = first > 0;
				var secondIsPositive = second > 0;
			
				var interIsPositive = true;
				if (firstIsPositive ^ secondIsPositive)
				{ interIsPositive = false; }

				var thirdIsPositive = third > 0;
				result = "+";
				if (interIsPositive ^ thirdIsPositive)
				{ result = "-"; }
			}

			// Write result
			jsConsole.writeLine("The sign of the product is: " + result);
		}
		else {
			jsConsole.writeLine("Wrong input.");
		}
	</script>
</body>
</html>
